package com.ycz.service.impl;

import com.ycz.commons.CodeMsg;
import com.ycz.commons.Constant;
import com.ycz.commons.Result;
import com.ycz.entity.Blog;
import com.ycz.form.BlogForm;
import com.ycz.mapper.BlogMapper;
import com.ycz.query.BlogQuery;
import com.ycz.service.BlogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ycz
 * @since 2021-10-10
 */
@Service
public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements BlogService {

    @Autowired
    private BlogMapper blogMapper;

    @Override
    public List<Blog> selectBlogByTitleAndContentAndDes(BlogQuery blogQuery) {

        return blogMapper.selectListByTitleByContentByDes(blogQuery);
    }

    @Override
    public Integer selectCount(BlogQuery blogQuery) {
        return blogMapper.selectCount(blogQuery);
    }

    @Override
    public Result selectArticleById(Integer id) {
        return new Result(blogMapper.selectArticleById(id));
    }

    @Override
    public Result insertBlog(BlogForm blogForm) {

        Integer i=blogMapper.insertBlog(blogForm);
        if (i>0){
            return new Result();
        }else {
            return new Result(CodeMsg.ERROR);
        }

    }

    @Override
    public Result updateById(BlogForm blogForm) {
        Integer i=blogMapper.updateById(blogForm);

        if (i>0){
            return new Result();
        }else {
            return new Result(CodeMsg.ERROR);
        }
    }
}
